package com.conexaoBanco;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import javax.naming.Context;
import javax.naming.InitialContext; 
import javax.sql.DataSource;

public class conexaoBanco {
 
	/*Connection con;
	public conexaoBanco() throws Exception {
		Context context = null;
		try {
			  context = new InitialContext();
	            Context initContext  = (Context)context.lookup("java:/comp/env");
	            DataSource ds = (DataSource)initContext.lookup("jdbc/jsp");
	            //DataSource ds = (DataSource)envContext.lookup("java:/comp/env/jdbc/testDB");
	            con = ds.getConnection();
		} catch (Exception e) {
			throw new Exception(
					"Nao foi possivel abrir conexao com banco de dados" + e);
		}
	}

	public void remove() {
		try {
			con.close();
		} catch (SQLException e) {
			System.out.println(e.getMessage());
		}
	}*/
	
	
public static Connection getConexao() throws Exception{
		Connection conn = null;
		try {
			DriverManager.registerDriver(new org.postgresql.Driver());
			conn = DriverManager.getConnection("" + "jdbc:postgresql://localhost:5432/jsp","postgres","123456");
			
		} catch (SQLException e) {
			 System.out.println("nao pode se conectar"+e);
		}
		
		return conn;
	}

}
